import store from '@/store';
import url from "@/axios/url";
const { mesUrl } = url();
import { getYesOrNotList, getLineCodeListNew } from "@/api/process/mesProcess";
import { getDict } from '@/api/common';
export const baseInfoMixin = {
  data () {
    const _this = this;
    const { type } = this.$route.query;
    return {
      baseInfoFormConfig: {
        span: 24,
        disabled: false,
        labelPosition: "right",
        labelWidth: "160px",
        isShowSubmitBtn: false,
        isShowBackBtn: false,
        formDesc: {
          technologyType: {
            type: "radio",
            label: $i18n.t("mesTechnology.technologyType2"),
            layout: 12,
            default: 'product',
            prop: {
              value: "value",
              text: "description",
            },
            options: async (data) => {
              const list = await getDict('technology_type');
              return list.data.result;
            },
            on: {
              change (data) {
                if (data === 'product') {
                  _this.baseInfoFormData.prodCode = '';
                  return;
                }
                if (data === 'series') {
                  _this.baseInfoFormData.seriesCode = '';
                  return;
                }
              }
            },
            disabled: () => {
              return type === '2'
            }
          },
          prodName: {
            layout: 12,
            type: "input",
            label: $i18n.t("mesTechnology.specifiedProduct"),
            required: true,
            vif: (data) => {
              return data.technologyType === 'product'
            },
            attrs: { readonly: true },
            slots: {
              prepend (h) {
                return (
                  <el-button disabled={true}>
                    {_this.baseInfoFormData.prodCode || $i18n.t("mesTechnology.none")}
                  </el-button>
                );
              },

              // 第一个参数是渲染函数，第二个参数是作用域插槽的数据
              append (h) {
                return (
                  <el-button
                    slot="append"
                    onClick={() => (_this.$refs.productDialog.drawer = true)}
                    icon="el-icon-search"
                  ></el-button>
                );
              },
            },
            disabled: () => {
              return type === '2'
            }
          },
          seriesName: {
            layout: 12,
            type: "input",
            label: $i18n.t("mesTechnology.seriesCode"),
            required: true,
            disabled: () => {
              return type === '2'
            },
            vif: (data) => {
              return data.technologyType === 'series'
            },
            attrs: { readonly: true },
            slots: {
              prepend (h) {
                return (
                  <el-button disabled={true}>
                    {_this.baseInfoFormData.seriesCode || $i18n.t("mesTechnology.none")}
                  </el-button>
                );
              },
              // 第一个参数是渲染函数，第二个参数是作用域插槽的数据
              append (h) {
                return (
                  <el-button
                    slot="append"
                    onClick={() => (_this.$refs.seriesDialog.drawer = true)}
                    icon="el-icon-search"
                    disabled={type != 4 && !!_this.baseInfoFormData.id}
                  ></el-button>
                );
              },
            },
          },
          technologyCode: {
            type: "input",
            label: $i18n.t("mesTechnology.technologyCode"),
            layout: 12,
            required: true,
            optionsLinkageFields: ["prodName,seriesName"],
            disabled: () => {
              // console.log('44444:', (data != undefined && data.technologyCode != undefined && data.technologyCode != ''))
              // return type === '2' || (_this.baseInfoFormData.technologyCode != undefined && _this.baseInfoFormData.technologyCode != undefined && _this.baseInfoFormData.technologyCode != '')
              return type === '2'
            }
          }
          ,
          technologyName: {
            type: "input",
            label: $i18n.t("mesTechnology.technologyName"),
            layout: 12,
            required: true,
          },
          isDefaultTechnology: {
            type: "radio",
            label: $i18n.t("mesTechnology.isDefaultTechnology"),
            layout: 12,
            default: '0',
            prop: {
              value: "value",
              text: "description",
            },
            options: async (data) => {
              const list = await getYesOrNotList();
              return list.data.result;
            },
          },
          workshopCode: {
            type: "select",
            label: $i18n.t("mesTechnology.workshopCode"),
            required: true,
            layout: 12,
            vif: (data) => {
              return data['isDefaultTechnology'] === '1';
            },
            prop: {
              value: "modelingCode",
              text: "modelingName",
            },
            options: async (data) => {
              const params = {
                modelingCode: this.$store.getters.factoryCode,
                level: 4,
                modelingType: "0",
              };
              const list = await getLineCodeListNew(params);
              this.workshopList = list.data.result;
              return list.data.result;
            },
            on: {
              change (val) {
                const findItem = _this.workshopList.find((item) => item.modelingCode == val) || {};
                _this.baseInfoFormData.workshopName = findItem.modelingName;
              },
            },
          },
          remark: {
            type: "textarea",
            label: $i18n.t("mesTechnology.remark"),
            required: false,
            layout: 24,
          },
        },
      },
    };
  },
};
